<?php

$host="127.0.0.1"; // Host name 
$username="root"; // Mysql username 
$password=null; // Mysql password 
$db_name="eldercaredb"; // Database name 
$tbl_name="user"; // Table name 

// Connect to server and select databse.
//mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
//mysql_select_db("$db_name")or die("cannot select DB");

// username and password sent from form 
//$loginusername=$_POST['loginusername']; 
//$password=$_POST['password']; 

// To protect MySQL injection (more detail about MySQL injection)
//$loginusername= stripslashes($loginusername);
//$password = stripslashes($password);
//$loginusername= mysql_real_escape_string($loginusername);
//$password = mysql_real_escape_string($password);
//$sql="SELECT username,password FROM $tbl_name WHERE username='$loginusername' and password='$password'";
//$result=mysql_query($sql);

// Mysql_num_row is counting table row
//$count=mysql_num_rows($result);

// If result matched $loginusername and $password, table row must be 1 row
//if($count>0){

// Register $loginusername, $password and redirect to file "AttendanceHome.php"
//$_SESSION['loginusername']==$loginusername;
//$_SESSION['password']==$password;
//header("location:AttendanceHome.php");
//}
//else {
//header("location: firstphp.php");
//$_POST[failed] = true;
//}


//session_start();
//	if (!isset($_SESSION["check"]))
//	{
//		$_SESSION["check"] = 0;
//	}
//	else if($_SESSION["check"] == 1)
//	{
//		echo "<p align='center'><font color =red>Please login to continue"; 
//		$_SESSION["check"] = 0;
//	}
//	if (!empty($_POST))
//	{
//		if (!empty($_POST['loginusername']) && !empty($_POST['password']))
	//	{
//			$loginusername = $_POST['loginusername'];
	//		$password = $_POST['password']; 
//			
//			$db = mysql_select_db ("eldercaredb" , $conn);
//			$qry = "SELECT username,password FROM $tbl_name WHERE username='$loginusername' and password='$password'";
//			$result = mysql_query($qry);
//			$num = mysql_num_rows($result);
//			if ($num >= 1)
//			{
///				{		
//					session_start();
//					$_SESSION["loginusername"] = $row["loginusername"];
//					$_SESSION["password"] = $row["password"];
//				}
//				Header("Location: AttendanceHome.php");
//				mysql_close($conn);
////			}
//			else if ($num == 0)
//			{
//				echo "<p align='center'> <font color=red> Please check your credentials and try again.";
//			}
//		}
//		else if (empty($_POST['loginusername']))
//		{
//			echo "<p align='center'> <font color=red> Username cannot be empty.";
//		}
//		else if (empty($_POST['password']))
//		{
//			echo "<p align='center'> <font color=red> Password cannot be empty.";
//		}
//	}
?>